import{Dt as e,H as t,M as n,Mt as r}from"./B603vO-13smUKN.js";function i(e,t){return e===t||typeof e==`number`&&typeof t==`number`&&Number.isNaN(e)&&Number.isNaN(t)}function a(o,s){if(e(o)&&e(s)){let c=Object.keys(s);for(let e of t(Object.keys(o),c))delete o[e];for(let t of c){let c=s[t],l=o[t];e(c)?e(l)?a(l,c):o[t]=r(c):Array.isArray(c)&&Array.isArray(l)?n(l,c)||(o[t]=c):i(c,l)||(o[t]=c)}}return o}function o(r,i){let a={};for(let e of t(Object.keys(r),Object.keys(i)))a[e]=null;for(let[t,s]of Object.entries(i)){let i=r[t];if(e(s)){let e=o(i??{},s);e!=null&&(a[t]=e)}else s==null&&i==null||n(s,i)||(a[t]=s??null)}return Object.keys(a).length>0?a:void 0}var s=new Set([`_id`,`_type`,`_v`,`_deleted`]),c=64;function l(e){return Array.isArray(e)&&e.length===2&&typeof e[0]==`number`&&typeof e[1]==`string`}function u(e,t){return Object.hasOwn(e,t)?e[t]:void 0}function d(t,n=0){if(n>=c)throw Error(`Change nesting is too deep.`);for(let[r,i]of Object.entries(t))if(!(s.has(r)||r.startsWith(`_`))){if(r.endsWith(`$`))throw Error(`Attribute name is not compliant.`);e(i)&&d(i,n+1)}}function f(e,t,n,r={}){return d(t),p(e,t,n,r)}function p(t,n,r,i){let{_type:a,_id:o}=n,c=typeof n._v==`number`&&Number.isFinite(n._v)?n._v:0;t??={obj:a==null?{_id:o}:{_id:o,_type:a},history:{}};let{obj:d,history:f}=t;for(let[t,a]of Object.entries(n)){if(s.has(t)||t.startsWith(`_`))continue;let n=u(d,t),m=i.mergers?.find(e=>e.match(n,a));if(m){d[t]=m.merge(n,a,{v:c,cid:r}),f[t]=[c,r],delete f[`${t}$`];continue}if(e(a)){let s=`${t}$`;if(e(n)){let e=u(f,t);(!l(e)||e[0]<c||e[0]===c&&r<e[1])&&(f[t]=[c,r])}else f[t]=[c,r],d[t]={},delete f[s];let m=u(f,s);(!m||l(m))&&(f[s]={}),p({obj:d[t],history:f[s]},{...a,_v:c,_id:o},r,i);continue}if(e(n))continue;let h=u(f,t),g=l(h)?h[0]:void 0,_=l(h)?h[1]:void 0;if(g==null||g<=c){if(g===c&&_!=null&&r>_)continue;f[t]=[c,r],delete f[`${t}$`],a==null?delete d[t]:d[t]=a}}return t}function m(e,t){return{obj:t==null?{_id:e}:{_id:e,_type:t},history:{}}}export{o as i,m as n,a as r,f as t};